<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../day48/demo/js/ajax.js"></script>
</head>
<body>
    
</body>
<script>
    function readText(url){
        var p = new Promise(function(resolve, reject){
            $.ajax({
                type: "get",
                url: url,
                success:function(text){
                    resolve(text);
                }
            })
        })
        return p ;
    }

    // ajax恐怖回调的解决方式1:
    // T = T1 + T2 + T3 
    var str = "";
    readText("1.txt").then(txt => {
        console.log(txt);
        str += txt;
        return readText("1.txt");
    }).then(txt => {
        console.log(txt);
        str += txt;
        return readText("1.txt");
    }).then(txt => {
        console.log(txt);
        str += txt;
        return str;
    }).then(txt => {
        console.log(txt);
    }).catch(err => {
        console.log("失败", err);
    })
</script>
</html>